import java.util.Vector;

import junit.framework.TestCase;
import org.imraniqbal.engine.*;
import org.imraniqbal.frogger.*;


public class CarTest extends TestCase {
	FroggerGame game;
	Map map;
	
	Car test1, test2, test3;
	
	public CarTest(String name) {
		super(name);
		
	}

	protected void setUp() throws Exception {
		super.setUp();
		map = new Map(30,30);
		test1 = new Car(5,5,Direction.LEFT,1,1);
		test2 = new Car(8,8,Direction.LEFT,1,1);
		test3 = new Car(10,10,Direction.RIGHT,1,1);
		game = new FroggerGame();
	}
	
	//MAPPABLE TESTS
	public void testGetSetX() {
		assertEquals(5,test1.getX()); //set to 5 originally
		test1.setX(2);
		assertEquals(2,test1.getX());
	}
	public void testGetSetY() {
		assertEquals(5,test1.getY()); //set to 5 originally
		test1.setY(2);
		assertEquals(2,test1.getY());
	}
	
	//PLAYER TESTS
	public void testSetGetDirection() {
		assertEquals(Direction.LEFT,test1.getDirection()); //default is left
		test1.setDirection(Direction.RIGHT);
		assertEquals(Direction.RIGHT,test1.getDirection());
	}
	public void testSetGetNumLives() {
		assertEquals(1,test1.getNumOflives()); //default is 3 lives
		test1.setNumOflives(5);
		assertEquals(5,test1.getNumOflives());
	}
	
	public void testUpdateLocationMovable() {
		//check 5,5 for the Player before it moves
		map.addMappable(test1);
		Vector<Mappable> temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		//attempt to move Player Left, Right, Up, Down
		assertEquals(true,test1.updateLocation(map)); //LEFT
		temp = map.getMappable(4,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.RIGHT); 
		assertEquals(true,test1.updateLocation(map)); //RIGHT
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.UP); 
		assertEquals(true,test1.updateLocation(map)); //UP
		temp = map.getMappable(5,4);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.DOWN); 
		assertEquals(true,test1.updateLocation(map)); //DOWN
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
	}
	public void testUpdateLocationCantMove() {
		//check 5,5 for the Player before it moves
		map.addMappable(test1);
		Vector<Mappable> temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		//add Walls around player, now it will never move
		map.addWall(4,5);
		map.addWall(6,5);
		map.addWall(5,4);
		map.addWall(5,6);
		//attempt to move Player Left, Right, Up, Down
		assertEquals(false,test1.updateLocation(map)); //LEFT
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.RIGHT); 
		assertEquals(false,test1.updateLocation(map)); //RIGHT
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.UP); 
		assertEquals(false,test1.updateLocation(map)); //UP
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.DOWN); 
		assertEquals(false,test1.updateLocation(map)); //DOWN
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
	}
	
	//CAR TESTS
	public void testConstructor() {
		Car testConstructor = new Car(5,5,Direction.LEFT,1,1);
		assertEquals(5, testConstructor.getX());
		assertEquals(5, testConstructor.getY());
		assertEquals(Direction.LEFT, testConstructor.getDirection());
		assertEquals(1, testConstructor.getNumOflives());
		assertEquals(1, testConstructor.getID());
	}

	public void testGetSetID() {
		assertEquals(1,test1.getID()); //test1 ID is set to 1 originally
		test1.setID(3);
		assertEquals(3,test1.getID());
		
	}
	
	public void testSpawnDie() {
		assertEquals(null,map.getMappable(5,5));
		test1.spawn(map);
		assertEquals(true,map.getMappable(5,5).contains(test1));
		
		//Cars can't die
		
	}
	
	public void testMoveCar() {
		test1.spawn(map);
		test2.spawn(map);
		test3.spawn(map);
		assertEquals(true, map.getMappable(5,5).contains(test1)); //somewhere in middle
		assertEquals(true, map.getMappable(8,8).contains(test2)); //left side of map
		assertEquals(true, map.getMappable(10,10).contains(test3)); //right side of map
		map.addWall(7,8); //will stop test2
		map.addWall(11,10); //will stop test3
		
		test1.moveCar(map);
		test2.moveCar(map);
		test3.moveCar(map);
		assertEquals(true, map.getMappable(4,5).contains(test1)); //somewhere in middle
		assertEquals(true, map.getMappable(17,8).contains(test2)); //car moved to right side
		assertEquals(true, map.getMappable(1,10).contains(test3)); //car moved to left side
		
	}
	
	
	
	
	
	

}











